using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace CreamX.Core.TileMap
{

    public struct Tile
    {
        public bool CanOccupy ;
        public int Type;
        public Rectangle TileRectangle;
        public Vector2 Origin;
        public Vector2 Location;
        public bool Flipped;
        public bool Visible;
        public float Rotation;
        public Tile(string newType, float tileWidth, float tileHeight, int cutsizex, int cutsizey)
        {
            Rotation = 0;
            CanOccupy = true;
            if(newType.Contains("X"))
            {
                Type = Math.Abs(int.Parse(newType.Substring(0,newType.Length-1)));
                CanOccupy = false;
            }
            else
            {
                if (newType.Contains("("))
                {
                    Type = Math.Abs(int.Parse(newType.Substring(0,newType.LastIndexOf("("))));
                    Rotation=MathHelper.ToRadians(90* int.Parse(newType.Substring(newType.LastIndexOf("(") +1,1)));
                    CanOccupy = true;
                }
                else
                {
                    CanOccupy = true;
                    Type = Math.Abs(int.Parse(newType));
                }
            }
            
            

            TileRectangle = new Rectangle(0, 0, cutsizex, cutsizey);
            Origin = new Vector2(0, 0);
            Location = new Vector2(0, 0);
            Flipped = false;
            Visible = true;
            
            //SetType( Type);
        }

    
        internal void SetType(float tilesx,float tilesy,float tilesize)
        {

            int __tx = (int)tilesx - 1;
            float X = Type % tilesx;
            float Y = (Type - (Type % tilesx)) / tilesx;
            TileRectangle.X=(int)(X  * tilesize);
            TileRectangle.Y =(int)( Y * tilesize);
        }
    }
}
